package com.example.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo.domain.entity.TrainClass;
import com.example.demo.domain.entity.TrainClassHomework;
import com.example.demo.param.TrainClassParam;
import com.example.demo.param.TrainClassUserParam;
import com.example.demo.service.TrainClassHomeworkService;
import com.example.demo.mapper.TrainClassHomeworkMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
* @author DaoJia
* @description 针对表【train_class_homework(培训系统-班级-作业关系)】的数据库操作Service实现
* @createDate 2024-02-01 21:45:53
*/
@Service
public class TrainClassHomeworkServiceImpl extends ServiceImpl<TrainClassHomeworkMapper, TrainClassHomework>
    implements TrainClassHomeworkService{

    @Resource
    private TrainClassHomeworkMapper trainClassHomeworkMapper;


    @Override
    public TrainClassHomework selectByHwIdAndClassId(Long homeworkId, Long trainClassId) {
        QueryWrapper<TrainClassHomework> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("homework_id", homeworkId)
                .eq("class_id", trainClassId);
        return trainClassHomeworkMapper.selectOne(queryWrapper);
    }

    @Override
    public void deleteByHwIdAndClassId(Long homeworkId, Long trainClassId) {
        QueryWrapper<TrainClassHomework> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("homework_id", homeworkId)
                .eq("class_id", trainClassId);
        trainClassHomeworkMapper.delete(queryWrapper);
    }

    @Override
    public Page<TrainClassHomework> queryByParam(TrainClassUserParam param) {
        QueryWrapper<TrainClassHomework> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("class_id", param.getTrainClassId());
        Page<TrainClassHomework> page = new Page<>(param.getPageNumber(), param.getPageSize());
        return trainClassHomeworkMapper.selectPage(page, queryWrapper);
    }
}




